package com.yyaccp.hncc.sms.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysUserService;
import com.yyaccp.hncc.sms.service.ISmsSkdRuleItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yyaccp.hncc.sms.mapper.SmsSkdRuleMapper;
import com.yyaccp.hncc.sms.domain.SmsSkdRule;
import com.yyaccp.hncc.sms.service.ISmsSkdRuleService;

import javax.annotation.Resource;

/**
 * 排班规则Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-08-09
 */
@Service
public class SmsSkdRuleServiceImpl implements ISmsSkdRuleService 
{
    @Resource
    private SmsSkdRuleMapper smsSkdRuleMapper;
    @Autowired
    private ISysUserService iSysUserService;
    @Autowired
    private ISmsSkdRuleItemService iSmsSkdRuleItemService;
    /**
     * 查询排班规则
     * 
     * @param id 排班规则ID
     * @return 排班规则
     */
    @Override
    public SmsSkdRule selectSmsSkdRuleById(Long id)
    {
        return smsSkdRuleMapper.selectSmsSkdRuleById(id);
    }

    /**
     * 查询排班规则列表
     * 
     * @param smsSkdRule 排班规则
     * @return 排班规则
     */
    @Override
    public List<SmsSkdRule> selectSmsSkdRuleList(SmsSkdRule smsSkdRule)
    {
        return smsSkdRuleMapper.selectSmsSkdRuleList(smsSkdRule);
    }

    /**
     * 新增排班规则
     * 
     * @param smsSkdRule 排班规则
     * @return 结果
     */
    @Override
    public int insertSmsSkdRule(SmsSkdRule smsSkdRule)
    {
        SysUser sysUser=iSysUserService.selectUserByUserName(SecurityUtils.getUsername());
        smsSkdRule.setOperateTime(new Date());
        smsSkdRule.setStatus(1);
        smsSkdRule.setOperatorId(sysUser.getUserId());
        int num=smsSkdRuleMapper.insertSmsSkdRule(smsSkdRule);
        int numTo=0;
        if(num>0){
            for (int i=0;i<smsSkdRule.getSmsSkdRuleltemList().size();i++){
                numTo=iSmsSkdRuleItemService.insertSmsSkdRuleItem(smsSkdRule.getSmsSkdRuleltemList().get(i));
            }
        }
        return numTo;
    }

    /**
     * 修改排班规则
     * 
     * @param smsSkdRule 排班规则
     * @return 结果
     */
    @Override
    public int updateSmsSkdRule(SmsSkdRule smsSkdRule)
    {
        return smsSkdRuleMapper.updateSmsSkdRule(smsSkdRule);
    }

    /**
     * 批量删除排班规则
     * 
     * @param ids 需要删除的排班规则ID
     * @return 结果
     */
    @Override
    public int deleteSmsSkdRuleByIds(Long[] ids)
    {
        return smsSkdRuleMapper.deleteSmsSkdRuleByIds(ids);
    }

    /**
     * 删除排班规则信息
     * 
     * @param id 排班规则ID
     * @return 结果
     */
    @Override
    public int deleteSmsSkdRuleById(Long id)
    {
        return smsSkdRuleMapper.deleteSmsSkdRuleById(id);
    }

    @Override
    public SmsSkdRule selectSmsSkdRuleDate() {
        return smsSkdRuleMapper.selectSmsSkdRuleDate();
    }

}
